package cn.pconline.autoclub.util.ubb.node;

import cn.pconline.autoclub.util.ubb.Node;

import java.util.Map;

/**
 *
 * @author xhchen
 */
public class EmotNodeWap extends AbstractNode {
	String emotRoot;
    Map<String, String> emotMap;

	public EmotNodeWap() {}

	private EmotNodeWap(String name, String attribute) {
		super.name = name;
		super.attribute = attribute;
	}

	public void setEmotRoot(String emotRoot) {
		this.emotRoot = emotRoot;
	}

    public void setEmotMap(Map<String, String> emotMap) {
        this.emotMap = emotMap;
    }

	@Override
	public StringBuilder getText(java.util.LinkedList<Node> stack) {
        StringBuilder sb = new StringBuilder();
        if ("em9001".equals(name)) {
            sb.append('{').append(name).append('}');
        } else {
            sb.append("<img src=\"")
                    .append(emotRoot)
                    .append('/')
                    .append(name)
                    .append(emotMap.get(name.length() > 2 ? name.substring(2, name.length()) : "") != null ? ".png" : ".gif")
                    .append("\"/>");
        }
        return sb;
	}

	@Override
	public void appendText(CharSequence text) {}

	@Override
	public Node copyWithoutText() {
		EmotNodeWap result = new EmotNodeWap(name, attribute);
		result.setEmotRoot(emotRoot);
        result.setEmotMap(emotMap);
		return result;
	}

	@Override
	public Node build(String name, String attribute) {
		EmotNodeWap result = new EmotNodeWap(name, attribute);
		result.setEmotRoot(emotRoot);
        result.setEmotMap(emotMap);
		return result;
	}
}
